/*========================================
取得標題列
=========================================*/
function get_head_custom() {
let ss = SpreadsheetApp.getActiveSpreadsheet()
let ws = ss.getSheetByName('day2');
let head_custom = ws.getSheetValues(1, 1, 1, ws.getLastColumn())[0];
console.log(head_custom);
return head_custom;
}
/*========================================
取得資料
=========================================*/
function get_data_custom() {
let ss = SpreadsheetApp.getActiveSpreadsheet()
let ws = ss.getSheetByName('day2');
if (ws.getLastRow() < 2) return [];//無資料
let data_custom = ws.getSheetValues(2, 1, ws.getLastRow() - 1, ws.getLastColumn());
console.log(data_custom);
return data_custom;
}
/*========================================
返回流水號 最大值+1
=========================================*/
function maxSn() {
let ss = SpreadsheetApp.getActiveSpreadsheet()
let ws = ss.getSheetByName('day2');
let colIndex = 1;
if (ws.getLastRow() < 2) return 1;//尚無資料,返回1
let colArray = ws.getRange(2, colIndex, ws.getLastRow() - 1).getValues();//getSheetValues(2, colIndex, ws.getLastRow() - 1, 1)
console.log(colArray);
let maxi = Math.max.apply(Math, colArray);//在嵌套數組展開並找到其中的最大值
console.log(maxi);
return maxi + 1;
}
這個函式,留到後面正式要「新增記錄」,再來調用